package com.xmg.leetCode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: mazhongqing
 * @Date: 2021/3/16 17:14
 */
public class No17 {


    public static void main(String[] args) {
        Solution17 sol = new Solution17();
        sol.letterCombinations("23");
    }
}

class Solution17 {
    private StringBuilder sb = new StringBuilder();
    private String[] map = {"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    // 结果集
    private List<String> res = new ArrayList<>();
    public List<String> letterCombinations(String digits) {
        if(digits==null || digits.length()==0){
            return res;
        }
        backtrack(digits,0);
        return res;
    }

    public void backtrack(String digits,int index){
        if(sb.length()==digits.length()){
            res.add(sb.toString());
            return;
        }
        String val = map[digits.charAt(index)-'2'];
        for(char ch:val.toCharArray()){
            sb.append(ch);
            backtrack(digits,index+1);
            sb.deleteCharAt(sb.length()-1);
        }
    }
}
